﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TowerDefense.Units;
using Microsoft.Xna.Framework;

namespace TowerDefense.Debuffs
{
    public class Slow : Effect
    {
        public Slow(TimeSpan duration, double movementSpeedModifier)
        {
            MovementSpeedModifier = movementSpeedModifier;
            this.Duration = duration;
        }

        public double MovementSpeedModifier
        {
            get;
            set;
        }

        public override void ApplyEffect(Creep C, GameTime gameTime)
        {
            this.Duration -= gameTime.ElapsedGameTime;
            C.CurrentSpeed = C.BaseSpeed * this.MovementSpeedModifier;

            List<Debuffs.Effect> removeEffects = new List<Effect>();

            foreach (Debuffs.Effect effect in C.UnderEffects.Where(e => e.GetType() == this.GetType()))
            {
                removeEffects.Add(effect);
            }
            foreach (Debuffs.Effect effect in removeEffects)
            {
                C.UnderEffects.Remove(effect);
            }

            C.UnderEffects.Add(this);
        }

        public override Effect Clone()
        {
            return new Slow(this.Duration, this.MovementSpeedModifier);
        }
    }
}
